<script lang="ts" setup>
  import { ref, unref, reactive } from 'vue';
  import { addAddress } from '../../../api/system/role';

  const rules = {
    name: {
      required: true,
      message: '请输入通讯人员姓名',
      trigger: 'blur',
    },
    phone: {
      required: true,
      message: '请输入通讯人员电话号码',
      trigger: ['input'],
    },
  };

  const formRef: any = ref(null);
  const defaultValueRef = () => ({
    name: '',
    phone: '',
  });

  let formValue = reactive(defaultValueRef());
  console.log(formValue);
  function resetForm() {
    formRef.value.restoreValidation();
    formValue = Object.assign(unref(formValue), defaultValueRef());
  }
</script>
<template>
  <div>
    <n-card :bordered="false" class="mt-4 proCard">
      <n-grid cols="1 s:1 m:3 l:3 xl:3 2xl:3" responsive="screen">
        <n-grid-item offset="0 s:0 m:1 l:1 xl:1 2xl:1">
          <n-form
            :label-width="80"
            :model="formValue"
            :rules="rules"
            label-placement="left"
            ref="formRef"
            class="py-8"
          >
            <n-form-item label="通讯人员姓名" path="name">
              <n-input v-model:value="formValue.name" placeholder="输入姓名" />
            </n-form-item>
            <n-form-item label="通讯人员号码" path="phone">
              <n-input placeholder="电话号码" v-model:value="formValue.phone" />
            </n-form-item>
            <div style="margin-left: 80px">
              <n-space>
                <n-button type="primary" @click="addAddress(formValue)">添加</n-button>
                <n-button @click="resetForm">重置</n-button>
              </n-space>
            </div>
          </n-form>
        </n-grid-item>
      </n-grid>
    </n-card>
  </div>
</template>
